-
Notifications
You must be signed in to change notification settings - Fork 469
[FreeBSD] support FreeBSD #861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few places that look like it's duplicating the __unix__
case. Otherwise I think this looks pretty good.
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@swift-ci please test |
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, (int)getpid()}; | ||
|
||
// get size we need | ||
if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should use ARRAY_SIZEOF
for the second parameter.
#define ARRAY_SIZEOF(array) (sizeof((array))/sizeof(*(array)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really think it's a good idea to introduce a macro, especially just for one place.
Although it makes it more readable, but I think it is reasonable to expect the next person who need to change this line are already familiar with the correct usage of sysctl
@@ -124,8 +124,17 @@ extension DispatchSource { | |||
public static let exit = ProcessEvent(rawValue: 0x80000000) | |||
public static let fork = ProcessEvent(rawValue: 0x40000000) | |||
public static let exec = ProcessEvent(rawValue: 0x20000000) | |||
#if os(FreeBSD) | |||
public static let track = ProcessEvent(rawValue: 0x00000001) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the different name? Should we not be using the name names to maintain source consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because NOTE_TRACK
is only available on FreeBSD but not Darwin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, having an extended FreeBSD only option is fine, but this does remove the signal
note doesn't it? I take it that NOTE_TRACK
is meant to replace that? If so, why not keep the name incongruous with the underlying note to allow easier porting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should've add more context in my previous reply. NOTE_SIGNAL
on Darwin and NOTE_TRACK
on FreeBSD are not interchangeable and each are platform specific.
NOTE_SIGNAL
on Darwin allow users to monitor if the process was sent a signal,
on the other hand, NOTE_TRACK
on FreeBSD cause kqueue to follow the target process across fork and automatically register events with same monitor. For example, NOTE_TRACK | NOTE_EXIT
on a pid cause exit event of the tracing process, and all its decedents to be reported.
It's not in this PR, but I just came across an additional build failure in the tests: swift-corelibs-libdispatch/tests/dispatch_workqueue.c Lines 33 to 47 in beb137b
I think we need to adjust the macro to edit: Realizing I didn't add the actual failure. |
@swift-ci please test |
@swift-ci please test Windows |
Will be addressing this in the next PR |
This patch adds FreeBSD support to libdispatch.
This patch is partly based on #561 with bug fixes and uses the pipe based mechanism based on #559 to bridge with CFRunLoop, since part of the CFRunLoop changes already landed in CoreFoundation.
In addition to above changes, also implements workqueue and limited DispatchSource support.